<?php
namespace PsiFramework\Plugins\Emailing\Classes\Model;

use PsiFramework\Classes\Model\Object;

use PsiFramework\Classes\Util\Object\ReferenceAttribute;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * Classe de variable de campagne d'e-mail
 *
 * @package Model
 */
class EmailVariable
{
    /**
     * 
     * @var string
     */
    protected /*string*/ $_key;
    
    /**
     * 
     * @var mixed
     */
    protected /*mixed*/ $_value;
    
    /**
     * Constructor
     */
    public function __construct(/*string*/ $key=null, /*string*/ $value=null)
    {
        $this->_key = $key;
        $this->_value = $value;
    }
    
    /**
     * 
     * @return string
     */
    public function getKey()
    {
        return $this->_key;
    }
    
    /**
     * 
     * @param string $key
     */
    public function setKey(/*string*/ $key)
    {
        $this->_key = $key;
    }
    
    /**
     * 
     * @return mixed
     */
    public function getValue()
    {
        return $this->_value;
    }
    
    /**
     * 
     * @param string $value
     */
    public function setValue(/**/ $value)
    {
        $this->_value = $value;
    }
    
    public function getRealValue(Object $obj=null)
    {
        if (is_null($this->_value)) {
            return '';
        }
        
        if ($this->_value instanceof ReferenceAttribute) {
            return $this->_value->getValue($obj);
        } else if (is_string($this->_value) || is_numeric($this->_value)) {
            return $this->_value;
        } else {
            return '';
        }
    }
}
